#include "gamewindow.h"
#include "ui_gamewindow.h"
#include "dataconfig.h"
#include"player.h"
#include<QMovie>
#include<QPixmap>
#include<QPainter>

GameWindow::GameWindow(int level,QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::GameWindow)
{
    ui->setupUi(this);
    dataconfig config;

    //画豆子
    QPixmap pix(50,50);
    QPainter painter(&pix);
    painter.setPen(Qt::white);
    painter.setBrush(Qt::white);
    painter.drawEllipse(QPoint(25,25),2,2);
    pix.save("D:\\pix.png");

    //共同背景初始化设置
    this->setFixedSize(1250,1000);
    ui->super_label->setVisible(false);
    ui->super_progressBar->setVisible(false);
    ui->slow_label->setVisible(false);
    ui->slow_progressBar->setVisible(false);

    //四个关卡背景设置
    for(int i=0;i<19;i++)
    {
        for(int j=0;j<19;j++)
        {
            this->game_array[i][j]=config.mData[level][i][j];
        }
    }

    for(int i=0;i<19;i++)
    {
        for(int j=0;j<19;j++)
        {
            label=new QLabel;
            label->setParent(this);
            label->setGeometry(0,0,50,50);
            if(game_array[i][j]==1)
            {
                switch (level)
                {
                    case 1:{QPixmap pix1=QPixmap(":/picture/Brick_1.png");label->setPixmap(pix1);break;}
                    case 2:{QPixmap pix2=QPixmap(":/picture/Brick_2.png");label->setPixmap(pix2);break;}
                    case 3:{QPixmap pix3=QPixmap(":/picture/Brick_5.png");label->setPixmap(pix3);break;}
                    case 4:{QPixmap pix4=QPixmap(":/picture/Brick_4.png");label->setPixmap(pix4);break;}
                }
            }
            else if(j==9&&i==10)
            {
                label->setMovie(m_player.pacman_left);
                label->setAlignment(Qt::AlignCenter);
                m_player.pacman_left->start();
            }
            else if(i==8&&(j==8||j==9||j==10))
            {
                label->setAlignment(Qt::AlignCenter);
                switch (j)
                {
                case 8:{label->setMovie(m_enemy.enemy1_left);m_enemy.enemy1_left->start();break;}
                case 9:{label->setMovie(m_enemy.enemy2_down);m_enemy.enemy2_down->start();break;}
                case 10:{label->setMovie(m_enemy.enemy3_right);m_enemy.enemy3_right->start();break;}
                }
            }
            else
            {
                label->setPixmap(pix);
            }
            label->move(j*50,i*50);
        }
    }
}

GameWindow::~GameWindow()
{
    delete ui;
}

void GameWindow::on_pushButton_clicked()
{
    close();
}
